package com.ruoyi.slope.monitorPoints.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.slope.dataFile.domain.SlopeDataFile;
import com.ruoyi.slope.dataFile.service.ISlopeDataFileService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.slope.monitorPoints.domain.SlopeMonitorpoints;
import com.ruoyi.slope.monitorPoints.service.ISlopeMonitorpointsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 监测点信息Controller
 * 
 * @author ruoyi
 * @date 2025-05-10
 */
@RestController
@RequestMapping("/slope/monitorpoints")
public class SlopeMonitorpointsController extends BaseController
{    
    @Autowired
    private ISlopeDataFileService slopeDataFileService;
    @Autowired
    private ISlopeMonitorpointsService slopeMonitorpointsService;

    /**
     * 查询监测点信息列表
     */
    @PreAuthorize("@ss.hasPermi('slope:monitorpoints:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlopeMonitorpoints slopeMonitorpoints)
    {
        startPage();
        List<SlopeMonitorpoints> list = slopeMonitorpointsService.selectSlopeMonitorpointsList(slopeMonitorpoints);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('slope:monitorpoints:list')")
    @GetMapping("/listMonitorPoints")
    public Map<String,String> listMonitorPoints(SlopeMonitorpoints slopeMonitorpoints)
    {
        slopeMonitorpoints.setDeptId(getDeptId());
        return slopeMonitorpointsService.selectSlopeMonitorPointsId(slopeMonitorpoints);
    }

    /**
     * 导出监测点信息列表
     */
    @PreAuthorize("@ss.hasPermi('slope:monitorpoints:export')")
    @Log(title = "监测点信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlopeMonitorpoints slopeMonitorpoints)
    {
        List<SlopeMonitorpoints> list = slopeMonitorpointsService.selectSlopeMonitorpointsList(slopeMonitorpoints);
        ExcelUtil<SlopeMonitorpoints> util = new ExcelUtil<SlopeMonitorpoints>(SlopeMonitorpoints.class);
        String path = util.exportExcel(response, list, "监测点信息数据"); 
        SlopeDataFile slopeDataFile = new SlopeDataFile();
        slopeDataFile.setFileName(path);
        slopeDataFileService.insertSlopeDataFile(slopeDataFile);
    }

    /**
     * 获取监测点信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('slope:monitorpoints:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(slopeMonitorpointsService.selectSlopeMonitorpointsById(id));
    }

    /**
     * 新增监测点信息
     */
    @PreAuthorize("@ss.hasPermi('slope:monitorpoints:add')")
    @Log(title = "监测点信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlopeMonitorpoints slopeMonitorpoints)
    {
        return toAjax(slopeMonitorpointsService.insertSlopeMonitorpoints(slopeMonitorpoints));
    }

    /**
     * 修改监测点信息
     */
    @PreAuthorize("@ss.hasPermi('slope:monitorpoints:edit')")
    @Log(title = "监测点信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlopeMonitorpoints slopeMonitorpoints)
    {
        return toAjax(slopeMonitorpointsService.updateSlopeMonitorpoints(slopeMonitorpoints));
    }

    /**
     * 删除监测点信息
     */
    @PreAuthorize("@ss.hasPermi('slope:monitorpoints:remove')")
    @Log(title = "监测点信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(slopeMonitorpointsService.deleteSlopeMonitorpointsByIds(ids));
    }
}
